/**
 * Created by fly on 2017/4/18.
 * 首页主要展示信息获取及功能逻辑
 */
var db = require('../db/connect_pool');
var Q = require('q');
// var doSqlPromise = require('../tools/promise').doSqlPromise();
/**
 * 执行sql语句promise
 * @param sql
 * @param value
 * @returns {*|promise}
 */
//todo 应该写到一个单独的文件中
function doSqlPromise (sql,value) {
    var deferred = Q.defer();
    db.query(sql,value,function (result) {
        deferred.resolve(result);
    });
    return deferred.promise;
}
/**
 * 获取装修步骤
 * @param callback
 */
exports.getFitStep = function (callback) {
    doSqlPromise('select * from fit_step')
        .then(function (result) {
            callback(result);
        });
}

/**
 * 获取装修案例
 * @param callback
 */
exports.getFitCase = function (callback) {
    doSqlPromise('select * from fitment_case limit 1,6')
        .then(function (result) {
            callback(result);
        });
}
/**
 * 获取首页展示商品
 * @param callback
 */
exports.getFitGoods = function (callback) {
    doSqlPromise('select * from fitment_goods order by id desc limit 1,3')
        .then(function (result) {
            callback(result);
        });
}
/**
 * 获取首页显示攻略文章
 * @param callback
 */
exports.getFitStrategy = function (callback) {
    doSqlPromise('select * from fitment_strategy order by id desc limit 0,3')
        .then(function (result) {
            callback(result);
        });
}